<template>
  <div>
    <u-head :title="tit"></u-head>
    <van-address-list
      v-model="choseId"
      :list="list"
      disabled-text=""
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>
<script>
import uHead from "../components/public/uHead.vue";
import { getAddressApi } from '@/api/orders/orders'
export default {
  components: {
    uHead,
  },
  data() {
    return {
      tit: "地址管理",
      list: [],
      choseId: '36'
    };
  },
  mounted(){
    this.getList()
  },
  methods:{
    onAdd(){
        this.$router.push('/increase')
    },
    onEdit(){

    },
    async getList(){
        let uid=JSON.parse( localStorage.getItem('user')).uid
        let res= await getAddressApi( {uid} )
        if(res.code==200){
            res.list.forEach((item,index)=>{
                if(index==0){
                    this.choseId=item.id
                }
                item.name=item.username
                item.tel=item.userphone
                item.address=item.location+item.useraddress
                this.list.push(item)
            })
        }else{
            alert(res.msg)
        }
        console.log(this.list);
    }
  }
};
</script>
<style>
.add {
  position: fixed;
  bottom: 0.3rem;
  left: 0;
}
</style>
